//
//  FictitiousHeaderView.m
//  ai2ban
//
//  Created by Heartbeats on 2018/1/11.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "FictitiousHeaderView.h"

@interface FictitiousHeaderView()
@property(nonatomic, strong) NSMutableArray *btn2Arrs;
@end

@implementation FictitiousHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.btn2Arrs = [[NSMutableArray alloc] init];
        [self initView];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

-(void) initView {
    NSArray *titles2 = @[@"价格",@"新品优先",@"综合排序"];
    CGFloat width1 = 60;
    CGFloat height1 = 30;
    CGFloat rightMargin1 = 12;
    CGFloat itemMarign = 20;
    [titles2 enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        CGFloat x = 0;
        if (idx == 2) {
            x = kScreen_Width-(rightMargin1+width1*2+itemMarign*2+width1);
        }
        if (idx == 1) {
            x = kScreen_Width-(rightMargin1+width1*2+itemMarign);
        }
        if (idx == 0) {
            x = kScreen_Width- rightMargin1-width1;
        }
        CGRect frame =  CGRectMake(x, 8, width1, height1);
        UIButton *btn = [[UIButton alloc] init];
        btn.frame = frame;
        [btn setTitle:obj forState:UIControlStateNormal];
        [btn setTitleColor:mainColor forState:UIControlStateSelected];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:btn];
        btn.tag = idx;
        [btn addTarget:self action:@selector(didBtnClick2:) forControlEvents:UIControlEventTouchUpInside];
        [self.btn2Arrs addObject:btn];
        if (idx == 2) {
            btn.selected = YES;
        }
    }];
}
- (void)didBtnClick2:(UIButton *)sender {
    [self.btn2Arrs enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.selected = NO;
    }];
    sender.selected = YES;
}


@end

